﻿//=====================================================================================================
// LocalizationLibrary
// The Localization Library is a collection of reusable software components that provide 
// support for localization. This library enables you to localize WPF, Silverlight and WP7 applications.
// (http://localizationlibrary.codeplex.com)
//=====================================================================================================
// Author: Nicola Gallo (Website: www.nicola.gallo.name, Email: nicolagmt@hotmail.it) 
//=====================================================================================================

namespace ReflectionStudio.LocalizationLibrary.Attributes
{
    //.NET References
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Defines a dynamic resource part and provides directive, for the engine, in case of version conflicting as well.
    /// Sets as default policy the value <see cref="VersionConflictPolicy.KeepExisting"/>.
    /// </summary>
    [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
    public class DynamicResourcePartAttribute : Attribute, ILocalizationAttribute
    {
        //Constructors

        /// <summary>
        /// Creates a new instance of the <see cref="DynamicResourcePartAttribute"/> class.
        /// </summary>
        /// <param name="resourceID">Specifies the resource's identifier.</param>
        /// <param name="language">The language of the <paramref name="value"/> parameter.</param>
        /// <param name="value">Resource's value for the language specified in the <paramref name="language"/> parameter.</param>
        /// <exception cref="ArgumentException">
        /// Thrown whether either <paramref name="resourceID"/> or <paramref name="value"/> parameter is either null or equals to white space and
        /// whether <paramref name="language"/> is an invalid language as well.
        /// </exception>
        public DynamicResourcePartAttribute(String resourceID, String language, Object value)
        {
            if (String.IsNullOrEmpty(resourceID))
            {
                throw new ArgumentException("resourceID parameter shouldn't be either null or equals at white space.");
            }
            else if (!LocalizationLibrary.Language.Validate(language))
            {
                throw new ArgumentException("language parameter is invalid.");
            }
            else if (value == null)
            {
                throw new ArgumentException("value parameter shouldn't be either null or equals at white space.");
            }
            this.ResourceID = resourceID;
            this.Language = language;
            this.Value = value;
            this.Policy = VersionConflictPolicy.KeepExisting;
        }

        //Properties

        /// <summary>
        /// Gets resource's identifier.
        /// </summary>
        public String ResourceID { get; private set; }

        /// <summary>
        /// Gets resource's language.
        /// </summary>
        public String Language { get; private set; }

        /// <summary>
        /// Gets resource's value.
        /// </summary>
        public Object Value { get; private set; }

        /// <summary>
        /// Gets/Sets the policy should accomplish the engine in case of version conflict.
        /// </summary>
        public VersionConflictPolicy Policy { get; set; }

        //Methods

        /// <summary>
        /// Serves as a hash function for <see cref="DynamicResourcePartAttribute"/> type.
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return this.ResourceID.GetHashCode();
        }

        /// <summary>
        /// Determines whether the specified <see cref="DynamicResourcePartAttribute"/> is equals to the current <see cref="DynamicResourcePartAttribute"/>.
        /// </summary>
        /// <param name="obj">Instance.</param>
        /// <returns>True whether the input instance is equals to the current instance otherwise false.</returns>
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return true;
            }
            else if ((obj == null) || (obj.GetType() != this.GetType()))
            {
                return false;
            }
            DynamicResourcePartAttribute instance = obj as DynamicResourcePartAttribute;
            return instance.ResourceID.Equals(this.ResourceID);
        }
    }

    /// <summary>
    /// Defines a dynamic resource part and provides directive, for the engine, in case of version conflicting as well.
    /// Sets as default policy the value <see cref="VersionConflictPolicy.KeepExisting"/>.
    /// </summary>
    [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
    public class CustomerViewAttribute : Attribute
    { 
      
        public CustomerViewAttribute(bool ContainsCustomerView)
        {
             
            this.ContainsCustomerView = ContainsCustomerView; 
        } 
        public bool ContainsCustomerView { get; private set; }
         
    }
}